//-----------------------------------------------------------------------------
//
// ImageLib Utility Sources
// Copyright (C) 2000-2002 by Denton Woods
// Last modified: 07/09/2002 <--Y2K Compliant! =]
//
// Filename: src-ILU/src/ilu_region.h
//
// Description: Creates an image region.
//
//-----------------------------------------------------------------------------

#ifndef ILU_REGION_H
#define ILU_REGION_H

#include "ilu_internal.h"


typedef struct Edge
{
	ILint	yUpper;
	ILfloat	xIntersect, dxPerScan;
	struct	Edge *next;
} Edge;


void ILAPIENTRY iluRegionfv(ILpointf *Points, ILuint n);

void ILAPIENTRY iluRegioniv(ILpointi *Points, ILuint n);



// Inserts edge into list in order of increasing xIntersect field.
void InsertEdge(Edge *list, Edge *edge);


// For an index, return y-coordinate of next nonhorizontal line
ILint yNext(ILint k, ILint cnt, ILpointi *pts);


// Store lower-y coordinate and inverse slope for each edge.  Adjust
//	and store upper-y coordinate for edges that are the lower member
//	of a monotonically increasing or decreasing pair of edges
void MakeEdgeRec(ILpointi lower, ILpointi upper, ILint yComp, Edge *edge, Edge *edges[]);

void BuildEdgeList(ILuint cnt, ILpointi *pts, Edge **edges);


void BuildActiveList(ILint scan, Edge *active, Edge *edges[]);


#define iRegionSetPixel(x,y) (iRegionMask[y * iluCurImage->Width + x] = 1 )


void FillScan(ILint scan, Edge *active);

void DeleteAfter(Edge *q);


// Delete completed edges.  Update 'xIntersect' field for others
void UpdateActiveList(ILint scan, Edge *active);


void ResortActiveList(Edge *active);


ILubyte *iScanFill();


#endif//ILU_REGION_H
